<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增导航')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-category-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">上级导航：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="treeId" name="pid" type="hidden" th:value="${mtoCategory?.id}"/>
                    <input class="form-control" type="text" onclick="selectCategoryTree()" id="treeName" readonly="true"
                           th:value="${mtoCategory?.name}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">导航名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">导航介绍：</label>
            <div class="col-sm-8">
                <input name="description" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-8">
                <input name="sort" class="form-control" type="text">
            </div>
        </div>

        <!--        类型  0 分类  ，1 页面-->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <input name="type" title="分类" type="radio" value="0">
                    <label value="0" th:text="分类"></label>
                </div>
                <div class="radio-box">
                    <input name="type" title="正常" type="radio" value="1">
                    <label value="1" th:text="页面"></label>
                </div>
            </div>
        </div>

        <!--        如果 type 为1，输入页面地址-->
        <div class="form-group">
            <label class="col-sm-3 control-label">请求地址：</label>
            <div class=" col-sm-8">
                <input id="pageUrl" name="pageUrl" class="type-drop form-control " type="text">
            </div>
        </div>

        <!--        状态  0 正常 ， 1 停用-->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <input name="status" title="正常" type="radio" value="1">
                    <label value="1" th:text="正常"></label>
                </div>
                <div class="radio-box">
                    <input name="status" title="停用" type="radio" value="0">
                    <label value="0" th:text="停用"></label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "mto/category"
    $("#form-category-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-category-add').serialize());
        }
    }

    /*导航表-新增-选择父导航表树*/
    function selectCategoryTree() {
        var options = {
            title: '导航表选择',
            width: "380",
            url: prefix + "/selectCategoryTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    /** 根据tupe判断是否隐藏，type = 1显示，0或其他隐藏*/
    $(function () {
        $('input').on('ifChecked', function (event) {
            var type = $("input[name=type]:checked").val();
            console.log(type)
            if (type == 1) {
                $("#pageUrl").parents(".form-group").show();
            } else {
                $("#pageUrl").parents(".form-group").hide();
            }
        });
    });
</script>
</body>
</html>
